package com.aash.web.wicket.page;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.aash.persistence.exception.DaoException;
import com.aash.service.UserService;
import com.aash.service.model.User;

public class HomePage extends WebPage {

	private final static transient Logger logger = LoggerFactory.getLogger(HomePage.class);
	
	private static final long serialVersionUID = 8264608801724756707L;
	
	private String email = "truc@machin";
	
	@SpringBean
	private UserService userService;
	
	public HomePage() {
		User current = null;
		try {
			current = userService.getUserByEmail(email);
		} catch (DaoException e) {
			logger.error(e.getMessage());
		}
		userService.createUser(email, "truc");
		try {
			current = userService.getUserByEmail(email);
		} catch (DaoException e) {
			logger.error(e.getMessage());
		}
		logger.info("User : " + current.getName());
		add(new Label("name", current.getName()));
		add(new Label("email", current.getEmail()));
	}
}
